import { Module } from '@nestjs/common';
import { FileController } from './file.controller';
import { FileService } from './file.service';
import { FileEntity } from './entities/file.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MulterModule } from '@nestjs/platform-express';
import * as multer from 'multer';
import { extname, join } from 'path';

@Module({
  imports: [
    TypeOrmModule.forFeature([FileEntity]),
    MulterModule.register({
      storage: multer.diskStorage({
        destination: join(__dirname, '../..', 'public/uploads'),
        filename: (req, file, cb) => cb(null, `${new Date().getTime() + extname(file.originalname)}`)
      })
    }),
  ],
  controllers: [FileController],
  providers: [FileService],
})
export class FileModule {}
